package tenantchannellogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type KbzpayInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewKbzpayInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KbzpayInfoLogic {
	return &KbzpayInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *KbzpayInfoLogic) KbzpayInfo(in *rpc.KbzpayInfoRequest) (*rpc.KbzpayInfoResponse, error) {
	var CommonResp rpc.CommonResp

	kbzpayModel := model.NewTenantChannelKbzpayModel(l.ctx, l.svcCtx.Db)
	kbzpay, err := kbzpayModel.GetKbzpayById(in.Id)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.KbzpayInfoResponse{
			CommonResp: &CommonResp,
		}, err
	}

	CommonResp.Message = "Success"
	return &rpc.KbzpayInfoResponse{
		Id:           kbzpay.ID,
		CreatedAt:    kbzpay.CreatedAt,
		UpdatedAt:    kbzpay.UpdatedAt,
		Code:         kbzpay.Code,
		Phone:        kbzpay.Phone,
		CardHolder:   kbzpay.CardHolder,
		MinAmount:    kbzpay.MinAmount,
		MaxAmount:    kbzpay.MaxAmount,
		DailyTimes:   kbzpay.DailyTimes,
		DailyAmount:  kbzpay.DailyAmount,
		RemainTimes:  kbzpay.RemainTimes,
		RemainAmount: kbzpay.RemainAmount,
		VisionLevel:  kbzpay.VisionLevel,
		IsDisplay:    kbzpay.IsDisplay,
		CommonResp:   &CommonResp,
	}, nil
}
